
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'dart:async';


class DateDemo extends StatefulWidget {
  @override
  _DateDemoState createState() => _DateDemoState();
}

class _DateDemoState extends State<DateDemo> {
   DateTime selectDate = DateTime.now();
   TimeOfDay selectedTime = TimeOfDay(hour: 9, minute: 30);
   _selectedTime() async{
  final TimeOfDay time = await showTimePicker(
      context: context, 
      initialTime: selectedTime, 

      );
      if(time == null) return;
      setState(() {
        selectedTime = time;
      });
  }

  _selectDate() async{
  final DateTime date = await showDatePicker(
      context: context, 
      initialDate: selectDate, 
      firstDate: DateTime(1900), 
      lastDate: DateTime(2100)
      );
      if(date == null) return;
      setState(() {
        selectDate = date;
      });
  }


  @override
  Widget build(BuildContext context) {
        return Scaffold(
        appBar: AppBar(
          title:Text('DateDemo'),
          elevation: 0.0,
        ),
        body: Container(
         padding: EdgeInsets.all(100),
         child: Column(
         mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                    InkWell(
                  onTap: _selectDate,
                  child: Row(
                    children: <Widget>[
                      Text(DateFormat.yMMMMd().format(selectDate)),
                      Icon(Icons.arrow_drop_down)
                    ],
                  ),
                 ),
                 InkWell(
                  onTap: _selectedTime,
                  child: Row(
                    children: <Widget>[
                      Text(selectedTime.format(context)),
                      Icon(Icons.arrow_drop_down)
                    ],
                  ),
                 ),
              ],
              
            ),
          ],
         ),
        ),
    );
  }
}